<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>医嘱列表</title>
		<link rel="stylesheet" type="text/css" href="../lib/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="searchlist.css" />
		<link rel="stylesheet" type="text/css" href="../css/reset.css" />
	</head>
	<body>
		<div class="ydhlui-detail-title clearfix">
			<div class="ydhlui-back fl"><a href="javascript:history.go(-1)">返回</a></div>
			<div class="ydhlui-tit fl"><span id="name"></span>&nbsp;&nbsp;&nbsp;&nbsp;住院号：<span id="admid"></span></div>
		</div>
		
		<div class="layui-tab layui-tab-brief" lay-filter="demo">
			<ul class="layui-tab-title">
				<li class="layui-this">长期医嘱</li>
				<li>临时医嘱</li>
			</ul>
		<div>
			
		<div class="type clearfix" id="type">
			<!-- 医嘱类型选择 -->
			<!-- <div class="fl ordtype layui-tab layui-tab-brief" lay-filter="ordtype">
				<span>医嘱类型：</span>
				<ul class="layui-tab-title">
					<li class="layui-this">全部</li>
					<li>用药</li>
					<li>检验</li>
					<li>说明</li>
					<li>手术</li>
					<li>输血</li>
				</ul>
			</div> -->
			<!-- 医嘱状态选择	 -->
			<!-- <div class="fl ordstatus layui-tab layui-tab-brief" lay-filter="ordstatus">
				<span>医嘱状态：</span>
				<ul class="layui-tab-title">
					<li class="layui-this">全部</li>
					<li>待审核</li>
				</ul>
			</div> -->
		</div>
			
			<!-- 表格 -->
			<table id="demo" lay-filter="list"></table>
			<!-- 表格操作 -->
			<script type="text/html" id="titleTpl">
				<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
				<a class="layui-btn layui-btn-xs" lay-event="stop">停止</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">作废</a>
			</script>
			<!-- 分页 -->
			<!-- <div id="test2"></div> -->
	</body>
	<script src="../js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/global.js" type="text/javascript" charset="utf-8"></script>
	<!-- <script src="./js/yzlb.js" type="text/javascript" charset="utf-8"></script> -->
	<script type="text/javascript">
		layui.use(['laypage', 'form', 'element', 'table','laytpl', 'util'], function() {
			var laytpl = layui.laytpl;
			var element = layui.element;
			var laypage = layui.laypage;
			var form = layui.form;
			var table = layui.table;
			var util = layui.util;
			
			
			function GetRequest() {
				var url = location.search; //获取url中"?"符后的字串
				console.log(url);
				var theRequest = new Object();
				if (url.indexOf("?") != -1) {
					var str = url.substr(1);
					strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			}
			var patientId = GetRequest().patientId;
			var patName = GetRequest().patName;
			var admid = GetRequest().admid;
			 $("#name").text(patName);
			  $("#admid").text(admid);
			// 默认参数 医嘱类型odc 
			var odc = "1",odt = "1",ods= "1",page="1",patientId=patientId;
			
			// 监听tab
			element.on('tab(demo)', function(data) {
				console.log(data.index+1);
				odc = data.index+1;
				doctorAdvicesearchList(odc,odt,ods,page)
			});
			
			element.on('tab(ordtype)', function(data) {
				console.log(data.index+1);
				odt = data.index+1;
				doctorAdvicesearchList(odc,odt,ods,page)
			});
			
			element.on('tab(ordstatus)', function(data) {
				console.log(data.index+1);
				ods = data.index+1;
				doctorAdvicesearchList(odc,odt,ods,page)
			});

			function doctorAdvicesearchList(odc,odt,ods,page) {
				// 请求参数
				var param = JSON.stringify({
					"body": 
					// {
					// 	"ordCategory": odc,
					// 	"ordStatus": ods,
					// 	"ordType": odt,
					// 	"currPage": page,
					// 	"pageSize": 10
					// },
					 {"patientId":patientId,"ordType":odc,"currPage":1,"pageSize":10}
					// ,
					// "header": {},
					// "token": {}
				});
				$.ajax({
					'type': 'post',
					'url': '/service-nursingwork/doctorAdvice/searchList',
					'data': param,
					'dataType': 'json',
					'contentType': "application/json",
					'success': function(data) {
						console.log(data);
						var len = data.data.length-1;
						var list = data.data.list;
						
						//表格
						table.render({
							elem: '#demo',
							height: 515,
							//toolbar: '#toolbarDemo',
							page: true, //一次请求全部数据前端自动分页
							cols: [
								[
									{field:'ord_type',title:'医嘱类型'},
									{field:'ord_create_time',title:'下达时间',templet: function(d) {
										return util.toDateString(d.create_time * 1000, "yyyy-MM-dd HH:mm:ss")
									}},
									{field:'ord_xtime',title:'停嘱时间',templet: function(d) {
										return util.toDateString(d.create_time * 1000, "yyyy-MM-dd HH:mm:ss")
									}},
									{field:'arcim_desc',title:'医嘱内容'},
									{field:'instr',title:'途径'},
									{field:'phfreq',title:'频率'},
									{field:'ord_user',title:'开嘱医生'},
									{field:'ord_status',title:'医嘱状态'},
									{field:'ord_start_time',title:'执行时间',templet: function(d) {
										return util.toDateString(d.create_time * 1000, "yyyy-MM-dd HH:mm:ss")
									} },
									{field:'title',title:'文章标题',width:200,templet:'#titleTpl'}
								]
							],
							data: data.data
						});
						
						
					},
					'error': function(res) {
						console.log(res);
					}
				});
			}

			doctorAdvicesearchList(odc,odt,ods,page)
			
			//监听行工具事件
			table.on('tool(list)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
				console.log(obj.data);
				console.log(obj.data.source_id);

				var data = obj.data //获得当前行数据
					,
					layEvent = obj.event; //获得 lay-event 对应的值
				if (layEvent === 'detail') {
					// layer.msg('查看操作');
					
					// 跳转详情...
					console.log(obj.data.source_id);
					window.location.href = "./advicedetail.html?id=" + obj.data.source_id;
				} else if (layEvent === 'del') {
					layer.confirm('是否确定作废此条医嘱', function(index) {
						obj.del(); //删除对应行（tr）的DOM结构
						layer.close(index);
						//向服务端发送删除指令
					});
				} else if (layEvent === 'stop') {
					layer.confirm('是否确定停止此条医嘱', function(index) {
						obj.del(); //删除对应行（tr）的DOM结构
						layer.close(index);
						//向服务端发送删除指令
					});
					
				}
			});
		})
	</script>
</html>
